package com.pzhu.dao.impl;

import com.pzhu.dao.BookDao;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;


import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @author Yancy xiao
 * @create 2023-04-17 8:43
 */
@Repository("bookDao")
@Scope("prototype")//singleton为单个bean（默认），prototype：创建的多个bean为多个对象
public class BookDaoImpl implements BookDao {

    //简单类型注入：整型、字符串
    @Value("100")
    private int connectionNum;

    @Value("tab")
    private String tabname;

    //配置文件注入
    @Value("${jdbc.username}")
    private String username;
    //配置文件注入
    @Value("${jdbc.url}")
    private String url;
    //配置文件注入
    @Value("${jdbc.password}")
    private String password;
    //配置文件注入
    @Value("${jdbc.driver}")
    private String driver;

    @Override
    public void save() {
        System.out.println(connectionNum);
        System.out.println(tabname);
        System.out.println(username);
        System.out.println(url);
        System.out.println(password);
        System.out.println(driver);
    }
    public BookDaoImpl() {
        System.out.println("book dao constructor ...");
    }

    @PostConstruct
    public void init() {
        System.out.println("book init ...");
    }

    @PreDestroy
    public void destroy() {
        System.out.println("book destory ...");
    }
}